# @Author   : 懒羊羊
# @File     : wk_login.py
# @Time     : 2024/12/23 18:01
import requests

from common.doLog import DoLog

dolog = DoLog().set_get_logger()


class Login:
    # 登录
    lg_url = "http://192.168.88.100:8080/login"
    lg_data = {'username': 'admin', 'password': '123456'}

    def login(self, url=None, data=None):

        if url == None or data == None:
            url = self.lg_url
            data = self.lg_data

        try:
            dolog.info("开始捕获异常了！")
            r = requests.post(url, data=data)
        except Exception as e:
            dolog.error(f"捕获到异常了！！！，异常提示是：{e}")
        else:
            dolog.info("没有出现异常！")
            return r
        finally:
            dolog.info("捕获异常结束了！")

    def get_token(self):
        token = self.login().json().get("Admin-Token")
        return token


if __name__ == '__main__':
    token = Login().get_token()
    print(token)
